package worldofbearcraft;

public abstract class Player implements IMortal {

	private boolean _death = false;
	private String _name;
	private int _hitPoints;
	protected int _armorClass;
	protected int _strength;
	protected int _intelligence;
	protected int _dexterity;
	protected int _attackPower;
	protected int _initiative;
	private int _dexModifier;
	private int _intModifier; 

	public Player(String name)

	{
		_name = name;

		int acRolls = Dice.statRoll();
		_armorClass = acRolls;

		int hpRolls = Dice.statRoll();
		_hitPoints = hpRolls;

		int stRolls = Dice.statRoll();
		_strength = stRolls;

		int dxRolls = Dice.statRoll();
		_dexterity = dxRolls;

		int inRolls = Dice.statRoll();
		_intelligence = inRolls;

		if (_dexterity < 5)
			_armorClass += 0;
		else if (_dexterity >= 5 && _dexterity < 10)
			_armorClass += 1;
		else if (_dexterity >= 10 && _dexterity < 15)
			_armorClass += 2;
		else if (_dexterity >= 15)
			_armorClass += 3;

		if (_dexterity < 5)
			_dexModifier += 0;
		else if (_dexterity >= 5 && _dexterity < 10)
			_dexModifier += 2;
		else if (_dexterity >= 10 && _dexterity < 15)
			_dexModifier += 4;
		else if (_dexterity >= 15)
			_dexModifier += 6;
		_initiative = Dice.initRoll() + _dexModifier;
		
		if (_intelligence < 5)
			_intModifier += 1;
		else if (_intelligence >= 5 && _dexterity < 10)
			_intModifier += 2;
		else if (_intelligence >= 10 && _dexterity < 15)
			_intModifier += 3;
		else if (_intelligence >= 15)
			_intModifier += 4;
		
		if (_strength < 5)
			_attackPower = 0;
		else if (_strength >= 5 && _strength < 10)
			_attackPower = 1;
		else if (_strength >= 10 && _strength < 15)
			_attackPower = 2;
		else if (_strength >= 15)
			_attackPower = 3;

		_initiative = Dice.initRoll() + _dexModifier;
		int _strModifier = _attackPower;

	}

	public void DisplayInfo() {
		System.out.println(_name);
		System.out.println("HP: " + _hitPoints);
		System.out.println("AC: " + _armorClass);
		System.out.println("ST: " + _strength);
		System.out.println("INT: " + _intelligence);
		System.out.println("DEX: " + _dexterity);
		System.out.println("AP: " + _attackPower);

	}

	public void Attack(Enemy e) {
		int _dmg = Dice.dmgRoll(6, 1);
		int _crit = _dmg * 2;
		int _atk = Dice.atkRoll();
		boolean hit = false;

		if (_atk == 20)
			_dmg = _crit;

		int _atkModified = _atk + _attackPower + 20;

		if (_atkModified >= e.getArmorClass())
			hit = true;
		else
			hit = false;

		if (hit == true) {

			System.out.println("The Player has hit the enemy for " + _dmg
					+ "damage.");
			e.setHitPoints(e.getHitPoints() - _dmg);
			if (e.getHitPoints() <= 0) {
				System.out.println("The Player " + _name + " has slain "
						+ e.getName() + " !");
				e.DieDramatically();
			} else
				System.out.println("Enemies remaining HP is "
						+ e.getHitPoints());
		} else {
			System.out
					.println("The Player has missed the enemy, with an modified attack value of : "
							+ _atkModified);
			System.out.println(" The " + e.getName()
					+ "'s total remaining HP is " + e.getHitPoints());
		}

	}

	public void Special(Enemy e){
		System.out.println("The Player has hit the enemy for " + getSpecialDmg
				+ "damage.");
		e.setHitPoints(e.getHitPoints() - _specialDmg);
		if (e.getHitPoints() <= 0) {
			System.out.println("The Player " + _name + " has slain "
					+ e.getName() + " !");
			e.DieDramatically();
		} else
			System.out.println("Enemies remaining HP is "
					+ e.getHitPoints());
	}

	public boolean getDeath() {
		return _death;
	}

	public int getHitPoints() {
		return _hitPoints;
	}

	public String getName() {
		return _name;
	}

	public int getDexterity() {
		return _dexterity;
	}

	public int getArmorClass() {
		return _armorClass;
	}

	public int getStrength() {
		return _strength;
	}

	public int getIntelligence() {
		return _intelligence;
	}

	public void setHitPoints(int value) {
		_hitPoints = value;
	}

	public int getInitiative() {
		return _initiative;
	}

	public int getIntModifier() {
		return _intModifier;
	}

	public void DieDramatically() {
		_death = true;
	}

}
